package com.mini.controller;

import com.mini.bean.OrderFrom;
import com.mini.utils.ResultDTO;
import com.mini.service.OrderformService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

//订单信息
@RestController
@RequestMapping("/Orderform")
public class OrderformController{

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private OrderformService orderformService;


    @RequestMapping(value ="/instOrder", method = RequestMethod.POST,produces= "application/json;charset=utf-8")
    @ResponseBody
    public ResultDTO instOrder(OrderFrom orderFrom) {

        try {
            orderFrom.setCreatetime(new Date());
            int a = orderformService.instOrder(orderFrom);
        }catch (Exception e){
            logger.info(""+e);
            return ResultDTO.getFailure("调用失败");
        }

        return ResultDTO.getSuccess(200,"成功");

    }

    /**
     * 获取订单列表
     * @param openid
     * @return
     */
//    TODO 开发到订单列表
    @RequestMapping(value ="/getOrderList", method = RequestMethod.GET,produces= "application/json;charset=utf-8")
    @ResponseBody
    public ResultDTO getOrderList(String openid) {
        List<OrderFrom> list=null;
        try {
            list=orderformService.getOrderList( openid);


        }catch (Exception e){
            logger.info(""+e);
            return ResultDTO.getFailure("调用失败");
        }

        return ResultDTO.getSuccess(200,"成功",list);


    }

    @RequestMapping(value="/getMap",produces={"application/json;charset=UTF-8;"})
    @ResponseBody
    public ResultDTO getMap(@RequestParam("lat") String lat, @RequestParam("lng") String lng) {
        List<OrderFrom> llist = null;

        try{

            llist= orderformService.selectGetMap(lat,lng);
        }catch (Exception e){
            logger.info(e+"");

            return ResultDTO.getFailure("调用失败");
        }

        return ResultDTO.getSuccess(200,"成功",llist);
    }




}
